home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / help_load.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-20  |  2.8 KB  |  98 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record
  3.  * Copyright (C) 1993 by Charles Sandmann (sandmann@clio.rice.edu)
  4.  * 
  5.  * This file is part of ED.
  6.  * 
  7.  * ED is free software; you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation.
  9.  * 
  10.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  11.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  13.  * 
  14.  * You should have received a copy of the GNU General Public License along with ED
  15.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  16.  * Mass Ave, Cambridge, MA 02139, USA.
  17.  */
  18. #include "opsys.h"
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. #include "library.h"
  24.  
  25. extern Char *help_get_text();
  26.  
  27. /******************************************************************************\
  28. |Routine: help_load
  29. |Callby: help
  30. |Purpose: Loads the online help library.
  31. |Arguments:
  32. |    fp is the file pointer of the online help file.
  33. |    retbase is the returned pointer to the created data structure.
  34. \******************************************************************************/
  35. void help_load(fp,retbase)
  36. FILE *fp;
  37. topic_ptr *retbase;
  38. {
  39.     topic_ptr base,cur,top;
  40.     subtopic_ptr sub,last;
  41.     Int level,curlevel;
  42.     Char *keyword;
  43.  
  44. /* allocate the base node */
  45.     base = (topic_ptr)imalloc(sizeof(topic_node));
  46.     base->first = NULL;
  47.     base->parent = NULL;
  48.     if(!(level = help_get_keyword(fp,&keyword)))
  49.     {
  50.         base->topic = keyword;    /* store top level keyword */
  51.         base->text = (Char *)help_get_text(fp);    /* store top level text */
  52.         level = help_get_keyword(fp,&keyword);    /* get first level 1 keyword (to match other block of the ifelse) */
  53.     }
  54.     else
  55.         base->topic = base->text = NULL;
  56.     cur = base;
  57.     curlevel = 1;
  58.     last = (subtopic_ptr)&cur->first;
  59. /* get subtopics (at this point, we just got a new keyword) */
  60.     do
  61.     {
  62.         if(level > curlevel)
  63.         {
  64.             cur = last->child;
  65.             curlevel++;
  66.             last = (subtopic_ptr)&cur->first;
  67.         }
  68.         if(level < curlevel)
  69.         {
  70.             while(level < curlevel)
  71.             {
  72.                 if(!(cur = cur->parent))
  73.                 {
  74.                     slip_message("Level 0 keyword found that was not at the beginning of the help file.");
  75.                     wait_message();
  76.                     *retbase = NULL;
  77.                     return;
  78.                 }
  79.                 curlevel--;
  80.             }
  81.             for(last = (subtopic_ptr)&cur->first;last->next;last = last->next);
  82.         }
  83.         sub = (subtopic_ptr)imalloc(sizeof(subtopic_node));
  84.         sub->keyword = keyword;
  85.         sub->next = NULL;
  86.         last->next = sub;    /* tie to current chain of subtopics */
  87.         last = sub;
  88.         sub->child = top = (topic_ptr)imalloc(sizeof(topic_node));
  89.         top->first = NULL;
  90.         top->parent = cur;
  91.         top->topic = keyword;
  92.         top->text = (Char *)help_get_text(fp);
  93.     } while((level = help_get_keyword(fp,&keyword)) > 0);
  94. /* return base of tree */
  95.     *retbase = base;
  96. }
  97.  
  98.